package com.global.college.adapter;

import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.global.college.R;

public class FilterItemAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int sortPosition = 0;
    private int levelPosition = 0;
    private int tagPosition = 0;

    private onSelectListener mListener;

    private int adapterType = 1;//1.排序、2.难度、3.课目

    public FilterItemAdapter(onSelectListener listener) {
        super(R.layout.item_filter);
        mListener = listener;
    }

    public interface onSelectListener {
        void onSeclect(int selectNum);
    }

    @Override
    protected void convert(BaseViewHolder helper, String name) {
        helper.setText(R.id.tv_filter_item_name, name);
        TextView textView = helper.getView(R.id.tv_filter_item_name);
        int position = 0;
        switch (adapterType) {
            case 1:
                position = sortPosition;
                break;
            case 2:
                position = levelPosition;
                break;
            case 3:
                position = tagPosition;
                break;
            default:
                break;
        }
        if (helper.getAdapterPosition() == position) {
            textView.setTextColor(mContext.getResources().getColor(R.color.color_red));
        } else {
            textView.setTextColor(mContext.getResources().getColor(R.color.text_black));
        }
        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (adapterType) {
                    case 1:
                        sortPosition = helper.getAdapterPosition();
                        break;
                    case 2:
                        levelPosition = helper.getAdapterPosition();
                        break;
                    case 3:
                        tagPosition = helper.getAdapterPosition();
                        break;
                    default:
                        break;
                }
                mListener.onSeclect(helper.getAdapterPosition());
                notifyDataSetChanged();
            }
        });
    }

    public void setAdapterType(int type) {
        adapterType = type;
    }
}
